﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xenta.Enums;
using Xenta.Operations;

namespace Xenta.Tests.Operations
{
    [TestFixture]
    public class ForumRankTests : OperationTest
    {
        protected override IEnumerable<Type> ModelMappings
        {
            get
            {
                return NHMappings.ALL;
            }
        }

        [TestCase(1)]
        public void Can_CRUD(int threshold)
        {
            var rank = Processor.Execute(new CreateForumRank
            {
                Flags = ForumRankFlags.None,
                Threshold = threshold
            }).Result;

            Assert.NotNull(rank);
            rank.Threshold.AreEqual(threshold);
            rank.AreEqual(Processor.Execute(new GetForumRank
            {
                EntityID = rank.EntityID
            }).Result);

            threshold = threshold + 1;
            var upd_rank = Processor.Execute(new UpdateForumRank
            {
                EntityID = rank.EntityID,
                Threshold = threshold,
                Flags = ForumRankFlags.Active
            }).Result;

            Assert.NotNull(upd_rank);
            upd_rank.AreEqual(rank);
            upd_rank.Threshold.AreEqual(threshold);
            upd_rank.Flags.AreEqual(ForumRankFlags.Active);

            Processor.Execute(new DeleteForumRank
            {
                EntityID = rank.EntityID
            });
        }

        [Test]
        public void Cannot_Create_If_Threshold_Lt_Zero()
        {
            Assert.Throws<ApplicationException>(() => Processor.Execute(new CreateForumRank
            {
                Threshold = -1
            }));
        }

        [Test]
        public void Cannot_Update_If_Threshold_Lt_Zero()
        {
            Assert.Throws<ApplicationException>(() => Processor.Execute(new UpdateForumRank
            {
                Threshold = -1
            }));
        }
    }
}
